package com.team.utils;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.io.IOException;

public class FileUploadUtil {

    public static String uploadFile(String savePath, CommonsMultipartFile file){
        try {
            String originalFilename = file.getOriginalFilename();
            String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
            String fileName = System.currentTimeMillis() + substring;

            File saveFile = new File(savePath+"/"+fileName);
            file.transferTo(saveFile);
            return fileName;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
